package com.ikangtai.shecare.stickycalendar;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.App;
import com.ikangtai.shecare.common.BaseActivity;
import com.ikangtai.shecare.common.baseView.ListBar;
import com.ikangtai.shecare.common.baseView.TopBar;
import com.ikangtai.shecare.common.util.AppLog;
import com.ikangtai.shecare.stickycalendar.adapter.MusListAdapter;
import com.ikangtai.shecare.stickycalendar.adapter.OvulationTestMoreAdapter;
import com.ikangtai.shecare.stickycalendar.adapter.RecordMoreAdapter;
import com.ikangtai.shecare.stickycalendar.bean.MoreReBean;
import com.ikangtai.shecare.stickycalendar.bean.OvulationMoreBean;
import com.ikangtai.shecare.stickycalendar.http.HCGValueHttp;
import com.ikangtai.shecare.stickycalendar.http.LHValueHttp;
import com.ikangtai.shecare.stickycalendar.http.util.HCGValueMsg;
import com.ikangtai.shecare.stickycalendar.http.util.LHValueMsg;
import com.orhanobut.dialogplus.DialogPlus;
import com.orhanobut.dialogplus.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lijinyuan on 16/8/10.
 */
public class RecordMoreActivity extends BaseActivity implements AdapterView.OnItemClickListener {
    private ListView listView;
    private List<MoreReBean> list;
    private List<String> stringsList;
    private List<OvulationMoreBean> ovulationMoreList;
    private List<OvulationMoreBean> redOvulationMoreList;
    private OvulationTestMoreAdapter ovulationTestMoreAdapter;
    private MusListAdapter musListAdapter;
    private OvulationTestMoreAdapter redOvulationTestMoreAdapter;
    private RecordMoreAdapter recordMoreAdapter;
    private TopBar topBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_record_more);
        list = new ArrayList<>();
        list.add(new MoreReBean(R.drawable.ca_item_5_img, "宫颈粘液", 0));
        list.add(new MoreReBean(R.drawable.ca_item_6_img, "排卵试纸", 0));
        list.add(new MoreReBean(R.drawable.ca_item_7_img, "早孕试纸", 0));
        list.add(new MoreReBean(R.drawable.ca_item_8_img, "设为排卵日", 1));
        list.add(new MoreReBean(R.drawable.ca_item_9_img, "备忘录", 0));

        listView = (ListView) findViewById(R.id.list_record_more);
        recordMoreAdapter = new RecordMoreAdapter(this, list);
        listView.setAdapter(recordMoreAdapter);
        listView.setOnItemClickListener(this);

        initView();

        initItem5();
        initItem6();
        initItem7();
        initItem8();
        initItem9();
    }

    private void initView() {
        topBar = (TopBar) findViewById(R.id.topBar);
        topBar.setOnTopBarClickListener(new TopBar.OnTopBarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void midLeftClick() {

            }

            @Override
            public void midRightClick() {

            }

            @Override
            public void rightClick() {

            }
        });
    }

    private void initItem5() {
        stringsList = new ArrayList<>();
        stringsList.add("1");
        musListAdapter = new MusListAdapter(this, stringsList);

    }

    //奇数为选中状态
    private void initItem6() {
        redOvulationMoreList = new ArrayList<>();
        redOvulationMoreList.add(new OvulationMoreBean(R.drawable.red_ovulation_more_list1, "无效（别紧张，请再试一次）", 3));
        redOvulationMoreList.add(new OvulationMoreBean(R.drawable.red_ovulation_more_list2, "阴性（加油，尖刺测试吧！）", 2));
        redOvulationMoreList.add(new OvulationMoreBean(R.drawable.red_ovulation_more_list3, "弱阳（再接再厉，不要错过强阳呦~）", 2));
        redOvulationMoreList.add(new OvulationMoreBean(R.drawable.red_ovulation_more_list4, "阳性（明后天会排卵）", 2));
        redOvulationMoreList.add(new OvulationMoreBean(R.drawable.red_ovulation_more_list5, "强阳（明后天会排卵）", 2));
        redOvulationTestMoreAdapter = new OvulationTestMoreAdapter(this, redOvulationMoreList);
    }

    private void initItem7() {
        ovulationMoreList = new ArrayList<>();
        ovulationMoreList.add(new OvulationMoreBean(R.drawable.ovulation_more_list1, "无效（别紧张，请再试一次）", 1));
        ovulationMoreList.add(new OvulationMoreBean(R.drawable.ovulation_more_list2, "阴性（别灰心，再接再厉！）", 0));
        ovulationMoreList.add(new OvulationMoreBean(R.drawable.ovulation_more_list3, "弱阳（恭喜你）", 0));
        ovulationMoreList.add(new OvulationMoreBean(R.drawable.ovulation_more_list4, "阳性（恭喜你）", 0));
        ovulationMoreList.add(new OvulationMoreBean(R.drawable.ovulation_more_list5, "强阳（恭喜你）", 0));
        ovulationTestMoreAdapter = new OvulationTestMoreAdapter(this, ovulationMoreList);

    }

    private void initItem8() {

    }

    private void initItem9() {



    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            case 0:
                DialogPlus dialog1 = DialogPlus.newDialog(this)
                        .setAdapter(musListAdapter)
//                        .setHeader(R.layout.mus_list_headerview)
//                        // This will enable the expand feature, (similar to android L share dialog)
//                        .setOnItemClickListener(new OnItemClickListener() {
//                            @Override
//                            public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
////                                redOvulationMoreList.get(position).setChoose(redOvulationMoreList.get(position).getChoose() == 0 ? 1 : 0);
//
//                                dialog.findViewById(R.id.header_view_save).setOnClickListener(new View.OnClickListener() {
//                                    @Override
//                                    public void onClick(View v) {
//                                        Toast.makeText(RecordMoreActivity.this, "position", Toast.LENGTH_SHORT).show();
//                                        //保存在此响应
//                                    }
//                                });
//                            }
//                        })

                        .create();

                dialog1.show();
                break;
            case 1:
                DialogPlus dialog2;
                LayoutInflater lif = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);


                dialog2 = DialogPlus.newDialog(this)
                        .setAdapter(redOvulationTestMoreAdapter)
                        .setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(DialogPlus dialog, Object item, View view, final int position) {
//                                redOvulationMoreList.get(position).setChoose(redOvulationMoreList.get(position).getChoose() == 0 ? 1 : 0);

                                for (int i = 0; i < redOvulationMoreList.size(); i++) {
                                    if (i == position) {
                                        redOvulationMoreList.get(i).setChoose(redOvulationMoreList.get(position).getChoose() == 2 ? 3 : 2);
                                    } else {
                                        redOvulationMoreList.get(i).setChoose(2);
                                    }
                                }
                                redOvulationTestMoreAdapter.notifyDataSetChanged();
                                dialog.findViewById(R.id.header_view_save).setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Toast.makeText(RecordMoreActivity.this, "position", Toast.LENGTH_SHORT).show();
                                        //保存在此响应
                                        AppLog.i("wzz---position---保存");

                                        List<LHValueMsg> lhValueMsgList = new ArrayList<LHValueMsg>();
                                        LHValueMsg lhValueMsg = new LHValueMsg();
                                        lhValueMsg.setDateRecord("2016-08-29");
                                        lhValueMsg.setLHResult(position);
                                        lhValueMsgList.add(lhValueMsg);
                                        LHValueHttp lhValueHttp = new LHValueHttp(RecordMoreActivity.this,lhValueMsgList);
                                        lhValueHttp.saveSelectedDayRecord();


                                    }
                                });
                            }
                        })


                        .setHeader(R.layout.redovulation_list_headerview)

                        // This will enable the expand feature, (similar to android L share dialog)
                        .create();
                dialog2.show();
                break;
            case 2:
                DialogPlus dialog3 = DialogPlus.newDialog(this)
                        .setAdapter(ovulationTestMoreAdapter)
                        .setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(DialogPlus dialog, Object item, View view, final int position) {
                                for (int i = 0; i < ovulationMoreList.size(); i++) {
                                    if (i == position) {
                                        ovulationMoreList.get(i).setChoose(ovulationMoreList.get(position).getChoose() == 0 ? 1 : 0);
                                    } else {
                                        ovulationMoreList.get(i).setChoose(0);
                                    }
                                }
                                ovulationTestMoreAdapter.notifyDataSetChanged();
                                dialog.findViewById(R.id.header_view_save).setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Toast.makeText(RecordMoreActivity.this, "position", Toast.LENGTH_SHORT).show();
                                        //保存在此响应

                                        List<HCGValueMsg> hcgValueMsgList = new ArrayList<HCGValueMsg>();
                                        HCGValueMsg hcgValueMsg = new HCGValueMsg();
                                        hcgValueMsg.setDateRecord("2016-08-29");
                                        hcgValueMsg.setHCGResult(position);
                                        hcgValueMsgList.add(hcgValueMsg);
                                        HCGValueHttp hcgValueHttp = new HCGValueHttp(RecordMoreActivity.this,hcgValueMsgList);
                                        hcgValueHttp.saveSelectedDayRecord();

                                    }
                                });
                            }
                        })

                        .setHeader(R.layout.ovulation_list_headerview)
                        .create();

                dialog3.show();
                break;


            case 4:

                startActivity(new Intent(RecordMoreActivity.this, NoteCalendarActivity.class)

                );
                break;
        }
    }
}
